<?php

namespace app\common\service;

class CommonTYService
{

    /**
     * 天眼物流接口
     * @param $url
     * @param null $data
     * @param null $header
     * @param bool $is_debug
     * @return mixed
     * @throws SystemErr
     */
    public static function TyLogistics($number,$mobile='',$type='')
    {
        date_default_timezone_set("Asia/Shanghai");
        $timestamp = time() * 1000;

        $apiUrl = "https://api.shumaidata.com/v4/express3/query";
        $method = "POST";

        $appid = "TGXXczk2P7yEckwF";
        $appsecurity = "TGXXczk2P7yEckwF5hpMZe1OYIQStn5l";
        $sign = substr(md5($appid . "&" . $timestamp . "&" . $appsecurity), false);

        //$type = "快递代号,不传将自动识别";
        //$number = "快递编号";
        //$mobile = "查顺丰时要输入寄件人或收件人手机号, 11位完整手机号或手机号后4位";

        $querys = "appid=".$appid."&timestamp=".$timestamp."&sign=".$sign."&type=".$type."&number=".$number."&mobile=".$mobile;

        $fullUrl = $apiUrl . "?" . $querys;

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($curl, CURLOPT_URL, $fullUrl);
        curl_setopt($curl, CURLOPT_FAILONERROR, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        $response = curl_exec($curl);
        curl_close($curl);
        $http_post_json = json_decode($response,true);
//        $http_post_json = $response;
        if($http_post_json['code'] == 200 && ($http_post_json['msg'] == '成功' || $http_post_json['msg'] == '操作成功')){
            return $http_post_json['data'];
        }else{
            return -1;
        }
        //return $re;
    }
}